package jskj.ekt.config;

import com.alibaba.dubbo.config.spring.ReferenceBean;
import jskj.ekt.api.dubbo.PushTest;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 描述:
 * ${DESCRIPTION}
 *
 * @author JSKJ
 * @create 2019-01-21 17:07
 */
public class PushBean<T> {

    String url;
    ClassPathXmlApplicationContext context;

    public PushBean(String url,ClassPathXmlApplicationContext context){
        this.url = url;
        this.context = context;
    }

    public T getPushBean(Class clazz){
        ReferenceBean<T> referenceBean = new ReferenceBean<T>();
        referenceBean.setApplicationContext(context);
        referenceBean.setInterface(clazz);
        referenceBean.setUrl(url);

        try {
            referenceBean.afterPropertiesSet();
            System.out.println("内******"+referenceBean.getId());
            return referenceBean.get();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
